from util.load_puzzles import load_puzzles_from_file
from puzzle.board import Board
from puzzle.mathF import Vec2
from puzzle.tile import TileDesc


g_board: Board = None # type: ignore
g_map: dict[complex, TileDesc] = {}
td17: TileDesc = None # type: ignore
td18: TileDesc = None # type: ignore

def gen_key(center: "Vec2") -> complex:
    x = int(center.x * 100)
    y = int(center.y * 100)
    return complex(x, y)

def setup():
    puzzles = list(load_puzzles_from_file("./puzzles.txt"))
    board = puzzles[0].board
    
    global g_board
    g_board = board

    global g_map
    for td in g_board.tiles_flatten:
        key = gen_key(td.center)
        if key in g_map:
            assert False
        else:
            g_map[key] = td
    
    global td17, td18
    td17 = g_board.get_td_by_label("17")
    td18 = g_board.get_td_by_label("18")

def run_once():
    v = td18.center - td17.center
    vr = v.rotate(60)
    
    end = td18.center + vr

    g_map.get(gen_key(end))

def run_repeat(repeat: int):
    for _ in range(repeat):
        run_once()